<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Freetype OpenGL: demo-gamma.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="content"><!-- do not remove this div! -->

<div id="top"><!-- do not remove this div! -->

  
  <div id="titlearea">
    
    <div id="projectname">Freetype OpenGL</div>
    
    
    <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
    
  </div>
  

<!--

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Freetype OpenGL
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>
-->


<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">demo-gamma.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">/* ============================================================================</span>
<span class="comment"> * Freetype GL - A C OpenGL Freetype engine</span>
<span class="comment"> * Platform:    Any</span>
<span class="comment"> * WWW:         http://code.google.com/p/freetype-gl/</span>
<span class="comment"> * ----------------------------------------------------------------------------</span>
<span class="comment"> * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.</span>
<span class="comment"> *</span>
<span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<span class="comment"> *</span>
<span class="comment"> *  1. Redistributions of source code must retain the above copyright notice,</span>
<span class="comment"> *     this list of conditions and the following disclaimer.</span>
<span class="comment"> *</span>
<span class="comment"> *  2. Redistributions in binary form must reproduce the above copyright</span>
<span class="comment"> *     notice, this list of conditions and the following disclaimer in the</span>
<span class="comment"> *     documentation and/or other materials provided with the distribution.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER &#39;&#39;AS IS&#39;&#39; AND ANY EXPRESS OR</span>
<span class="comment"> * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
<span class="comment"> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO</span>
<span class="comment"> * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,</span>
<span class="comment"> * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<span class="comment"> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<span class="comment"> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<span class="comment"> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</span>
<span class="comment"> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span class="comment"> *</span>
<span class="comment"> * The views and conclusions contained in the software and documentation are</span>
<span class="comment"> * those of the authors and should not be interpreted as representing official</span>
<span class="comment"> * policies, either expressed or implied, of Nicolas P. Rougier.</span>
<span class="comment"> * ============================================================================</span>
<span class="comment"> *</span>
<span class="comment"> * Example showing gamma influence</span>
<span class="comment"> *</span>
<span class="comment"> * ============================================================================</span>
<span class="comment"> */</span>
<span class="preprocessor">#include &quot;freetype-gl.h&quot;</span>

<span class="preprocessor">#include &quot;<a class="code" href="font-manager_8h.html">font-manager.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="vertex-buffer_8h.html">vertex-buffer.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="text-buffer_8h.html">text-buffer.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="markup_8h.html">markup.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="shader_8h.html">shader.h</a>&quot;</span>


<span class="comment">// ------------------------------------------------------- typedef &amp; struct ---</span>
<span class="keyword">typedef</span> <span class="keyword">struct </span>{
    <span class="keywordtype">float</span> x, y, z;
    <span class="keywordtype">float</span> r, g, b;
} vertex_t;

<span class="comment">// ------------------------------------------------------- global variables ---</span>
<a name="_a0"></a><a class="code" href="structtext__buffer__t.html" title="Text buffer structure.">text_buffer_t</a> *text_buffer;
<a name="_a1"></a><a class="code" href="structvertex__buffer__t.html" title="Generic vertex buffer.">vertex_buffer_t</a> *buffer;


<span class="comment">// ---------------------------------------------------------------- display ---</span>
<span class="keywordtype">void</span> display( <span class="keywordtype">void</span> )
{
    glClearColor( 1.0,1.0,1.0,1.0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glDisable( GL_TEXTURE_2D );
    <a name="a2"></a><a class="code" href="group__vertex-buffer.html#ga48df5bafd9315aabfb7f14bedb778c16" title="Render vertex buffer.">vertex_buffer_render</a>( buffer, GL_TRIANGLES, <span class="stringliteral">&quot;vc&quot;</span> );
    <a name="a3"></a><a class="code" href="group__text-buffer.html#gadbcccef4916637e046f5b342f195d635" title="Render a text buffer.">text_buffer_render</a>( text_buffer );
    glutSwapBuffers( );
}


<span class="comment">// ---------------------------------------------------------------- reshape ---</span>
<span class="keywordtype">void</span> reshape(<span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glutPostRedisplay();
}


<span class="comment">// --------------------------------------------------------------- keyboard ---</span>
<span class="keywordtype">void</span> keyboard( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> key, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y )
{
    <span class="keywordflow">if</span> ( key == 27 )
    {
        exit( 1 );
    }
}


<span class="comment">// ------------------------------------------------------------------- main ---</span>
<span class="keywordtype">int</span> main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv )
{
    glutInit( &amp;argc, argv );
    glutInitWindowSize( 512, 512 );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( argv[0] );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );

    buffer = <a name="a4"></a><a class="code" href="group__vertex-buffer.html#ga309c1129a1028f251fe6e6c3c1534a42" title="Creates an empty vertex buffer.">vertex_buffer_new</a>( <span class="stringliteral">&quot;v3f:c3f&quot;</span> );
    vertex_t vertices[4*2] = { {  0,  0,0, 1,1,1}, {  0,256,0, 1,1,1},
                               {512,256,0, 1,1,1}, {512,  0,0, 1,1,1},
                               {0,  256,0, 0,0,0}, {  0,512,0, 0,0,0},
                               {512,512,0, 0,0,0}, {512,256,0, 0,0,0} };
    GLuint indices[4*3] = { 0,1,2, 0,2,3, 4,5,6, 4,6,7 };
    <a name="a5"></a><a class="code" href="group__vertex-buffer.html#ga6cefde8ec247bcf71ff62409b2aa056a" title="Append a new item to the collection.">vertex_buffer_push_back</a>( buffer, vertices, 8, indices, 12 );
    

    text_buffer = <a name="a6"></a><a class="code" href="group__text-buffer.html#gad40995db39664d6d3f9da68d386a99da" title="Creates a new empty text buffer.">text_buffer_new</a>( <a name="a7"></a><a class="code" href="text-buffer_8h.html#aeb06e08fcb145b25caf33204ae04c7b7" title="Use LCD filtering.">LCD_FILTERING_ON</a> );
    <a name="_a8"></a><a class="code" href="unionvec4.html" title="Tuple of 4 floats.">vec4</a> white = {{1.0, 1.0, 1.0, 1.0}};
    <a class="code" href="unionvec4.html" title="Tuple of 4 floats.">vec4</a> black = {{0.0, 0.0, 0.0, 1.0}};
    <a class="code" href="unionvec4.html" title="Tuple of 4 floats.">vec4</a> none  = {{1.0, 1.0, 1.0, 0.0}};
    <a name="_a9"></a><a class="code" href="structmarkup__t.html" title="Simple structure that describes text properties.">markup_t</a> markup = {
        .<a name="a10"></a><a class="code" href="structmarkup__t.html#adcb67782935faf6178ef7afde350ca2a" title="A font family name such as &quot;normal&quot;, &quot;sans&quot;, &quot;serif&quot; or &quot;monospace&quot;.">family</a>  = <span class="stringliteral">&quot;fonts/Vera.ttf&quot;</span>,
        .size    = 15.0, .bold    = 0,   .italic  = 0,
        .rise    = 0.0,  .spacing = 0.0, .gamma   = 1.0,
        .foreground_color    = white, .background_color    = none,
        .underline           = 0,     .underline_color     = none,
        .overline            = 0,     .overline_color      = none,
        .strikethrough       = 0,     .strikethrough_color = none,
        .font = 0,
    };

    <span class="keywordtype">size_t</span> i;
    <a name="_a11"></a><a class="code" href="unionvec2.html" title="Tuple of 2 floats.">vec2</a> pen = {{32, 500}};
    <span class="keywordtype">wchar_t</span> *text = L<span class="stringliteral">&quot;A Quick Brown Fox Jumps Over The Lazy Dog 0123456789\n&quot;</span>;
    <span class="keywordflow">for</span>( i=0; i &lt; 14; ++i )
    {
        markup.<a name="a12"></a><a class="code" href="structmarkup__t.html#a37164c55ed3ed10f00ce0b2da6b9d2f5" title="Gamma correction.">gamma</a> = 0.75 + 1.5*i*(1.0/14);
        <a name="a13"></a><a class="code" href="group__text-buffer.html#ga7d8bb02091e52fb172209510fef2f036" title="Add some text to the text buffer.">text_buffer_add_text</a>( text_buffer, &amp;pen, &amp;markup, text, wcslen(text) );
    }
    pen = (<a class="code" href="unionvec2.html" title="Tuple of 2 floats.">vec2</a>) {{32, 234}};
    markup.<a name="a14"></a><a class="code" href="structmarkup__t.html#a04c930fd29432569aee47e56b59e3d79" title="Text color.">foreground_color</a> = black;
    <span class="keywordflow">for</span>( i=0; i &lt; 14; ++i )
    {
        markup.<a class="code" href="structmarkup__t.html#a37164c55ed3ed10f00ce0b2da6b9d2f5" title="Gamma correction.">gamma</a> = 0.75 + 1.5*i*(1.0/14);
        <a class="code" href="group__text-buffer.html#ga7d8bb02091e52fb172209510fef2f036" title="Add some text to the text buffer.">text_buffer_add_text</a>( text_buffer, &amp;pen, &amp;markup, text, wcslen(text) );
    }

    glutMainLoop( );
    <span class="keywordflow">return</span> 0;
}
</pre></div> </div><!-- contents -->
</div>
</body>
</html>
